#ifndef PARSER_H
#define PARSER_H

#include <string>
#include <vector>
#include <iostream>
#include <fstream>
//#include "simple_file_parser.h"

class Parser {
public:
    Parser(const std::string& filename);
    Parser(std::istream& stream);
    virtual ~Parser();

    void open_file(const std::string& p_file_name);
    void set_stream(std::istream& stream);
    void init();

    int match(int& value);
    int match(double& value);
    int match(std::string& value);

    int match_int(int& value);
    int match_double(double& value);
    int match_char(const std::string& char_set);
    int match_word(const std::string& pattern, bool ignore_case = true);
    int match_any_word(std::string& word);

    void next_line();
    void read_line(std::string& line);
    void backup(int count);
    bool line_done();
    bool eof();
    void set_charset(const std::string& ws,
                     const std::string& sc);

protected:
    bool matches(const std::string& s, int initial_state);
    void tokenize();

    std::vector<std::string> tokens;
    std::string single_char_tokens;
    std::string whitespace;

    std::istream* input;

    int n_tokens;
    int i_token;
    std::string file_name;
    int line_number;

    int buffer_size;
    char* input_line;
    std::string cur_line;
    std::string nxt_line;
};

#endif
